Skip to content

feat(stamphog): make size_gate.max_lines delegable per folder - #91348

Merged
trunk-io[bot] merged 6 commits into
masterfrom
feat/stamphog-delegable-max-lines
Sep 1, 2026
Merged

feat(stamphog): make size_gate.max_lines delegable per folder#91348
trunk-io[bot] merged 6 commits into
masterfrom
feat/stamphog-delegable-max-lines

Conversation

@charlesvien

@charlesvien charlesvien commented Aug 30, 2026

Copy link
Copy Markdown
Member

Problem

A folder AGENT_APPROVALS.md can raise stamphog's file ceiling for its own files, but not the 800 line ceiling. Teams with larger PRs on average get no per-folder relief.

Changes

  • size_gate.max_lines is now delegable, ceiling 1000, alone or next to max_files.
  • Lines get the same per-scope budget as files, so a folder grant covers only its own files.
  • A folder that grants one key inherits the other from its nearest ancestor grant, or the global value.
  • Line overrun refusals now name the scope, like file overruns already do.
  • products/desktop/AGENT_APPROVALS.md grants max_lines: 1000, so desktop PRs up to 1000 substantive lines stay eligible for auto-review.
  • Mechanical: ScopeBudget and the evidence JSON gain max_lines, both policy.yml files declare the key, docs updated.

How did you test this code?

  • Ran the pr-approval-agent suite and the backend policy-defaults tests locally.
  • New test_policy.py cases cover lines-only grants, child and parent key inheritance, over-ceiling max_lines and per-scope line overruns.

@charlesvien charlesvien self-assigned this Aug 30, 2026
@trunk-io

trunk-io Bot commented Aug 30, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

@charlesvien
charlesvien marked this pull request as ready for review August 30, 2026 06:42
@charlesvien
charlesvien requested a review from webjunkie August 30, 2026 06:43
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team August 30, 2026 06:43
@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
products/stamphog/packages/pr-approval-agent/policy.py:657-668
**Inherited file budgets multiply**

When a folder grants only `max_lines`, `resolve` creates a separate scope with a fresh copy of the global or ancestor `max_files` allowance. Because `_check_size` checks each scope independently, 20 substantive desktop files and 20 global files pass the nominal 20-file gate even though no folder granted a higher file limit.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Raise desktop line ceiling to 1000 via f..." | Re-trigger Greptile

Comment thread products/stamphog/packages/pr-approval-agent/policy.py Outdated
Comment thread products/stamphog/packages/pr-approval-agent/policy.py Outdated
@veria-ai

veria-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@hosthog

hosthog Bot commented Aug 30, 2026

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

The previews for this PR have been torn down and no longer serve.

@charlesvien charlesvien added the desktop-skip-backend-check Skip the check that blocks desktop and backend changes in one PR label Aug 30, 2026 — with PostHog
A folder that granted one size_gate key was given a fresh copy of the other
key's global ceiling, which created a second budget nobody delegated: a
lines-only grant let a PR touch 30 folder files plus 30 global files, and a
files-only grant let it add 800 folder lines plus 800 global lines.

Each ceiling now resolves on its own chain walk. A file counts against the
nearest folder granting that ceiling and against the global pool when the chain
grants it nowhere, so a one-key grant leaves its files in the pool they were
already in for the other key.

Generated-By: PostHog Desktop
Task-Id: dd27894e-233a-469b-ada8-c80d13d67405
Generated-By: PostHog Desktop
Task-Id: dd27894e-233a-469b-ada8-c80d13d67405
The size-gate helpers returned same-typed pairs, which the
tuple-return-prefer-dataclass rule blocks: callers can swap the two scope
tuples, or the two counts, without a type error.

_size_budgets now returns the EffectivePolicy the scopes already live on, and
the per-scope file filter returns the file list so substantive_size stays the
one place that unpacks a count pair.

Generated-By: PostHog Desktop
Task-Id: dd27894e-233a-469b-ada8-c80d13d67405
@charlesvien charlesvien added the stamphog Request AI approval (no full review) label Aug 30, 2026 — with PostHog
@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Aug 30, 2026
@PostHog PostHog deleted a comment from stamphog Bot Aug 30, 2026
@webjunkie

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T06:35:42.137751Z c0e8b7e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: c0e8b7e917

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@webjunkie webjunkie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Agent review, actively steered by @webjunkie. Every claim names its evidence.

Approving. The delegation mechanics are correct. One adjustment to consider, not a blocker.

Verified

  • Per-key chain resolution works as documented, and a mixed grant with one over-ceiling key invalidates the whole file (test_policy.py, one-key-over-ceiling).
  • The evidence JSON scopes shape change breaks no consumer. Nothing in products/stamphog/backend, products/stamphog/mcp, or the generated frontend types reads it.
  • The desktop grant covers what its prose claims. packages/core, packages/ui, and apps/ all sit under products/desktop/.

Consider restoring a whole-PR total

_check_size no longer compares anything to the whole-PR size. The old if lines > max_lines is gone, and lines, files = substantive_size(self.pr.files) now only decorates the refusal strings. Every check is per-scope, and scope count is unbounded.

PR shape this PR allows with a roof
global only 800 800
desktop only 1000 1000
desktop plus global 1800 1000
desktop plus 4 more granting folders 4800 1000

That conflicts with the rationale this PR keeps in pr-approval-agent/README.md: "past ~800 the merged-unchanged rate collapses". The threshold was derived from PR size, not per-folder size.

max(s.ceiling for s in budgets.line_scopes) compared to the whole-PR lines closes it, and the same expression over file_scopes closes the pre-existing files case. It needs no new key, since every grant is already validated at or under the contract ceiling. With no grant in play it equals the global default, so it is the deleted check with one variable swapped. It leaks no headroom, because the per-scope budgets still cap the global pool at 800.

Refutable. If per-scope budgets are meant to sum without bound, both READMEs should say so, and the "~800" rationale needs rewording because it no longer describes any check.

A stacked PR with this change follows, to accept or drop.

@webjunkie

Copy link
Copy Markdown
Contributor

/trunk merge

@trunk-io
trunk-io Bot merged commit e40b3bc into master Sep 1, 2026
249 of 251 checks passed
@trunk-io
trunk-io Bot deleted the feat/stamphog-delegable-max-lines branch September 1, 2026 07:04
@deployment-status-posthog

deployment-status-posthog Bot commented Sep 1, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-09-01 07:37 UTC Run
prod-us ✅ Deployed 2026-09-01 07:55 UTC Run
prod-eu ✅ Deployed 2026-09-01 07:57 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop-skip-backend-check Skip the check that blocks desktop and backend changes in one PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants